#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;

const ll maxn{ll(1e8+5)};
ll n,q,tot,ans[maxn];
bitset<maxn> f;

void init(){
    for(ll i{2};i<=n;i++){
        if(!f[i]){
            for(ll j{i+i};j<=n;j+=i){
                f[j]=1;
            }
        }
    }
}

struct CinNum{
    char c;
    ll n;
    CinNum &operator>>(ll &num){
        c=n=0;
        while(!isdigit(c)){
            c=getchar();
        }
        while(isdigit(c)){
            n=n*10+c-'0';
            c=getchar();
        }
        num=n;
        return *this;
    }
}cinn;

#define cin cinn

int main(){
    iostream::sync_with_stdio(0)/*,cin.tie(0)*/,cout.tie(0);
    cin>>n>>q;
    init();
    for(ll i{2};i<=n;i++){
        if(!f[i]){
            ans[++tot]=i;
        }
    }
    while(q--){
        ll k;
        cin>>k;
        cout<<ans[k]<<'\n';
    }
}